<?php
load_info_var($cf_controller);											//加载smarty变量
load_file('goods_class',LIB_PATH);
$main = new Goods($db);
$id = isset($_POST['id']) ? intval($_POST['id']) : intval($_GET['id']);
$return_page = $cf_pre_page ? $cf_pre_page : $cf_self_page;
//print_r($cf_admin_info);
switch($cf_action){
	case "index":
		if($cf_ispost){
			
			$item_list = array();			
			for($i=0;$i<7;$i++){
				$cate_key = 'item_cate'.$i;
				$id_key = 'item_id'.$i;
				$title_key = 'item_title'.$i;
				$price_key = 'item_price'.$i;
				$status_key = 'item_status'.$i;
				$id_list = '';
				
				
				if($_POST[$cate_key]){
					foreach($_POST[$title_key] as $key=>$item)	{
						$title = $item;
						$id = $_POST[$id_key][$key];
						$price = $_POST[$price_key][$key];
						$status = $_POST[$status_key][$key];
						if($id && $title && $price){
							$id_list .= $id_list ? ','.$id : $id;	
						}
					}
					if($id_list){
						$item_info = array('title'=>$_POST[$cate_key],'status'=>$_POST[$status_key],'list'=>$id_list);
						$item_list[] = $item_info;
					}
				}

			}
			
			if($item_list){
				$new_array = var_export($item_list,true);
				$input_data= "\$cf_custom_goods=".$new_array;
				write_file(INFO_PATH."cf_custom_goods".$type.".php",$input_data);	
				my_jump('信息提交成功','',$cf_self_page."?dpt=".$cf_dpt,1);
			}else{
				my_jump('请添加信息');	
			}
		}else{
			$smarty->mypage($cf_controller,$cf_action,0);	
			$data_ary = $main->get_custome_goods();
			//dump($data_ary);
		}
		
		//dump($data_ary);
	break;
	
	
	
	default:
		my_jump('非法操作!');
	break;
}

$smarty->assign(array(
	'id'=>$id,
	'rid'=>$rid,
	'row'=>$row,
	'data_ary'=>$data_ary,	
	'page'=>$page,
	'skey' => $skey,
	'stype' => $stype,
	'fee_sort' => $fee_sort,
	'cf_action' => $cf_action,

));
$smarty->mydisplay();

?>